package com.mobiletrain.org.motherkitch.shequ;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lidroid.xutils.BitmapUtils;
import com.mobiletrain.org.motherkitch.R;
import com.mobiletrain.org.motherkitch.utils.ImageLoad;

import java.util.ArrayList;

/**
 * Created by lenovo on 2015/4/26.
 */
public class SheQuDetailAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private ArrayList<SheQuDetailClass> data;

    public SheQuDetailAdapter(Context context, ArrayList<SheQuDetailClass> data) {
        this.context = context;
        this.data = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if(data!=null){
            return data.size();
        }
        return 0;
    }

    @Override
    public int getViewTypeCount() {
        return 3;
    }

    @Override
    public int getItemViewType(int position) {
        if(data.get(position).getType().equals("1")){
            return 0;
        }
        return 1;
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        switch (getItemViewType(position)) {
            //文本
            case 0:
                TextView text = null;
                if (convertView == null) {
                    text = new TextView(context);
                } else {
                    text = (TextView) convertView;
                }
                SheQuDetailClass sheQuDetailClass = data.get(position);
                text.setText(sheQuDetailClass.getContent());
                text.setTextSize(18);
                text.setTextColor(Color.BLACK);
                return text;
            //图片
            case 1:
                ImageView view;
                if (convertView == null) {
                    view = new ImageView(context);
                } else {
                    view = (ImageView) convertView;
                }
                SheQuDetailClass sheQuDetailClass1 = data.get(position);
                view.setMaxWidth(ViewGroup.LayoutParams.MATCH_PARENT);
                BitmapUtils bitmapUtils = ImageLoad.getBitmapUtils(context);
                bitmapUtils.display(view, sheQuDetailClass1.getContent());
                return view;

        }
        return null;

    }




}
